package logic

import (
	"context"
	"login/loginrpc/loginrpcclient"

	"login/api/internal/svc"
	"login/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRegisterUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterUserLogic {
	return &RegisterUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RegisterUserLogic) RegisterUser(req *types.RegisterUserRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	user, err := l.svcCtx.LoginRpc.RegisterUser(l.ctx, &loginrpcclient.RegisterUserRequest{
		Account:    req.Account,
		Password:   req.Passwor,
		Captcha:    req.Captcha,
		SmsCaptcha: req.SmsCaptch,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "用户注册成功",
		Code:    200,
		Data:    user,
	}, nil

}
